home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / business / qfaxv107.zip / MANYFAX.C < prev    next >
C/C++ Source or Header  |  1996-09-15  |  6KB  |  155 lines

  1. /*************************************************************************/
  2. /*  MANYFAX.C     Send many faxes automatically by calling QFAX.EXE      */
  3. /*          Copyright (C) 1996 Anthony Mai. All rights reserved          */
  4. /*                                                                       */
  5. /*  You may modify and use this program for any purpose as long as this  */
  6. /*  copyright notice remains intact. But you may not re-distribute this  */
  7. /*  file except when you distribute it in it's original form, as part of */
  8. /*  the QFAXV107.ZIP shareware package.                                  */
  9. /*************************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <process.h>
  14.  
  15. int i,j,k,Ans, returncode;
  16. char qfaxcmd[128]; tmpstr[128];
  17. char listname[64], logname[64];
  18. char filename[20], phone[20];
  19. char dirnam[128];
  20. FILE * fbase, * ftemp;
  21.  
  22. usage()
  23. {
  24.  printf("Usage of this program is:\n"
  25.         "  manyfax  -db fax_list_file -log log_file_name\n"
  26.         "Example:\n"
  27.         "  manyfax  -db manyfax.fdb  -log manyfax.log\n"
  28.         "Contact 102773.370@CompuServe.com if there is a problem.\n");
  29. }
  30.  
  31. main(argc, argv)
  32.   int argc;
  33.   char * argv[];
  34. {
  35.   _asm {
  36.     mov  ax, 03h
  37.     int  10h
  38.    }
  39.  
  40.   printf("\nThis program demonstrate how to call QFAX from other programs\n"
  41.          "and send out many faxes to different fax numbers\n\n");
  42.   printf("You can use the spawl function in C to invoke QFAX from your program\n");
  43.   printf("The file manyfax.fdb is a plain ASCII file that stores file names\n"
  44.          "and fax numbers like this format:\n\n");
  45.   printf("File#1      Fax_Number#1\n"
  46.          "File#2      Fax_Number#2\n"
  47.          "File#3      Fax_Number#3\n...\n\n");
  48.  
  49.  
  50.  /* Find the the name of the directory where manyfax.exe and qfax.exe is */
  51.  strcpy(dirnam, argv[0]);
  52.  i = strlen(dirnam)-1;
  53.  while (i>0 && (*(dirnam+i) != '\134')) i--;
  54.  *(dirnam+i+1) = '\0';
  55.  
  56.  if (argc == 1) {usage(); exit(-1);}
  57.   
  58.   /*  Construct the QFAX command with the path name */
  59.   strcpy(qfaxcmd, dirnam);
  60.   strcat(qfaxcmd, "\\");
  61.   strcat(qfaxcmd, "qfax.exe");
  62.  
  63.   /* Test whether the the QFAX path and file name is correct or not */
  64.   if ((ftemp = fopen(qfaxcmd, "rb")) == NULL) {
  65.       printf("%s can not be found!\n", qfaxcmd); exit(-1);
  66.      }
  67.   else fclose(ftemp);
  68.  
  69.   strcpy(listname, "manyfax.fdb");
  70.   strcpy(logname,  "manyfax.log");
  71.  
  72.   i = 1;
  73.   while (i<argc)
  74.    {
  75.     if (*(argv[i]) == '-') switch (*(argv[i]+1)) {
  76.       case 'd': i++; strcpy(listname, argv[i]); break;
  77.       case 'l': i++; strcpy(logname,  argv[i]); break;
  78.      }
  79.     i ++;
  80.    }
  81.  
  82.   if ((fbase = fopen(listname, "rb")) == NULL) {
  83.      printf("Database file %s not found\n", listname); exit(-1);
  84.     }
  85.   if ((ftemp = fopen(logname, "wb")) == NULL) {
  86.      printf("Can not create file %s\n", logname); exit(-1);
  87.     }
  88.  
  89.   while (!feof(fbase)) {
  90.     filename[0] = 0x00; phone[0] = 0x00;
  91.     fscanf(fbase, "%s", filename);
  92.     if (strlen(filename)) {
  93.        fscanf(fbase, "%s", phone);
  94.        if (strlen(phone)) {
  95.          printf("Trying to fax %s to %s using QFAX\n", filename, phone);
  96.          
  97.          /* Call QFAX as a command line faxer */
  98.  
  99.          returncode = spawnl(_P_WAIT, qfaxcmd, "qfax", "-nod",
  100.            filename, phone, NULL);
  101.  
  102.          /* The above is similar to DOS command line:                   */
  103.          /*    qfax -nod filename phone                                 */
  104.  
  105.          fprintf(ftemp, "%s -> %s  return code = %d : ",filename,phone,returncode);
  106.  
  107.          printf("QFAX called. ");
  108.          switch(returncode) {
  109.             case  0: printf (       "FAX Successful.\n");
  110.                      fprintf(ftemp, "FAX Successful.\n");
  111.                      break;
  112.             case -1: printf (       "File, Memory or Modem errors.\n");
  113.                      fprintf(ftemp, "File, Memory or Modem errors.\n");
  114.                      break;
  115.             case  1: printf (       "FAX partially completed.\n");
  116.                      fprintf(ftemp, "FAX partially completed.\n");
  117.                      break;
  118.             case  2: printf (       "No FAX page transmitted.\n");
  119.                      fprintf(ftemp, "No FAX page transmitted.\n");
  120.                      break;
  121.             case  3: printf (       "FAX handshake failed.\n");
  122.                      fprintf(ftemp, "FAX handshake failed.\n");
  123.                      break;
  124.             case  4: printf (       "Unknown error after dialing.\n");
  125.                      fprintf(ftemp, "Unknown error after dialing.\n");
  126.                      break;
  127.             case  5: printf (       "Unable to Start FAX.\n");
  128.                      fprintf(ftemp, "Unable to Start FAX.\n");
  129.                      break;
  130.             case  6: printf (       "Unable to reset or initialize modem.\n");
  131.                      fprintf(ftemp, "Unable to reset or initialize modem.\n");
  132.                      break;
  133.             case 10: printf (       "No Dial Tone on Phone Line.\n");
  134.                      fprintf(ftemp, "No Dial Tone on Phone Line.\n");
  135.                      break;
  136.             case 11: printf (       "Phone Line Busy.\n");
  137.                      fprintf(ftemp, "Phone Line Busy.\n");
  138.                      break;
  139.             case 12: printf (       "Fax Connection Time Out.\n");
  140.                      fprintf(ftemp, "Fax Connection Time Out.\n");
  141.                      break;
  142.             default: printf (       "Unknown FAX error.\n");
  143.                      fprintf(ftemp, "Unknown FAX error.\n");
  144.                      break;
  145.           }
  146.          for (j=0; j<32767; j++) {/* This is just a time delay*/}
  147.         }
  148.       }
  149.    }
  150.  
  151.   fclose(ftemp);
  152.   fclose(fbase);
  153.   printf("All done. Read the file %s for a log of fax results\n", logname);
  154. }
  155.